#!/bin/bash

echo "========================================"
echo "短链接服务启动脚本"
echo "========================================"
echo

echo "检查Java环境..."
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java环境，请先安装JDK 21"
    exit 1
fi

echo "检查Maven环境..."
if ! command -v mvn &> /dev/null; then
    echo "错误: 未找到Maven环境，请先安装Maven"
    exit 1
fi

echo "检查MySQL服务..."
if ! pgrep -x "mysqld" > /dev/null; then
    echo "警告: MySQL服务可能未启动，请确保MySQL服务正在运行"
    echo
fi

echo "检查Redis服务..."
if ! pgrep -x "redis-server" > /dev/null; then
    echo "警告: Redis服务可能未启动，请确保Redis服务正在运行"
    echo
fi

echo "开始构建项目..."
mvn clean compile

echo
echo "启动短链接服务..."
echo "服务启动后，请访问: http://localhost:8080"
echo "按 Ctrl+C 停止服务"
echo

mvn spring-boot:run
